import { Component, OnInit } from '@angular/core';
import { User } from 'src/app/domain/user';
import { UserConfirm } from 'src/app/domain/user-confirm';
import {AdministrativeService} from '../../service/administrative.service'
/*

@Author:刘洋

@Date: 2018-12-12

@员工信息注册功能实现

@Last Modified time: 2018-12-16
*/
@Component({
  selector: 'app-administrative-register',
  templateUrl: './administrative-register.component.html',
  styleUrls: ['./administrative-register.component.css']
})
export class AdministrativeRegisterComponent implements OnInit {

  constructor(private administrativeService:AdministrativeService) { }
  id: number;//
  user_name: string;//
  name: string;//
  age: number;//
  sex: string;//
  department: string; //部门
  position: string; //职务
  annual_leave_length: number;
  password:string;
  repassword:string;
  ngOnInit() {
  }
  registerMan(){
    if(this.id == undefined|| this.user_name == undefined||this.name==undefined||this.age == undefined||this.sex==undefined||this.password==undefined){
      alert("输入不能为空！");
    }
    else if(this.password !== this.repassword)
      alert("两次输入的密码不一致！");
    else{
      var user:User = {
        id: this.id,
        user_name: this.user_name,
        name: this.name,
        age: this.age,
        sex: this.sex,
        department: this.department, //部门
        position: this.position, //职务
        annual_leave_length: this.annual_leave_length, //年假上限
        remain_annual_leave: this.annual_leave_length //剩余年假
      };
      var userConfirm:UserConfirm = {
        id:this.id,
        password:this.password
      };
      this.administrativeService.addUser(user)
      .subscribe();
      this.administrativeService.addUserConfirm(userConfirm)
      .subscribe(()=>{alert("注册成功");},(error)=>{
        alert("注册失败");
      });
    }
  }

}
